﻿using System;
using System.Data;
using System.Data.Common;
using System.Text;

using LTJ.Common.Generic;
using LTJ.Entity;

namespace LTJ.Data
{
    public interface IDataProvider
    {
        #region 用户操作
        /// <summary>
        /// 创建新用户.
        /// </summary>
        /// <param name="userinfo">用户信息</param>
        /// <returns>返回用户ID, 如果已存在该用户名则返回-1</returns>
        int CreateUser(UserInfo userinfo);
        /// <summary>
        /// 根据用户ID返回用户实体
        /// </summary>
        IDataReader GetUserInfoByID(int uid);
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        IDataReader GetUserInfoByName(string userName);
        /// <summary>
        /// 获取用户分页数据
        /// </summary>
        DataTable GetUsersByPage(int pageindex, int pagesize, string condition, string orderstr);
        /// <summary>
        /// 获取用户数量
        /// </summary>
        int GetUsersCount(string cons);
        bool UpdateUser(UserInfo uinfo);
        int RemoveUser(string ids, int gid);
        /// <summary>
        /// 检查密码
        /// </summary>
        /// <param name="uid">用户id</param>
        /// <param name="passWord">密码</param>
        /// <param name="originalPassword">是否非MD5密码</param>
        /// <returns>如果用户密码正确则返回uid, 否则返回-1</returns>
        IDataReader CheckPassword(int uid, string passWord, bool originalPassword);
        /// <summary>
        /// 检查密码
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="passWord">密码</param>
        /// <param name="originalPassWord">是否为未MD5密码</param>
        /// <returns>如果正确则返回uid</returns>
        IDataReader CheckPassword(string userName, string passWord, bool originalPassWord);
        int DelUser(string ids);
        /// <summary>
        /// 更新用户状态信息
        /// </summary>
        bool UpdateUserStatus(string ids, int status);
        /// <summary>
        /// 更新用户所属管理员ID
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="fid">管理员ID</param>
        bool UpdateUserFid(int uid, int fid);
        /// <summary>
        /// 批量更新用户所属管理员ID
        /// </summary>
        bool UpdateUsersFid(int fid, string ids);
        /// <summary>
        /// 设置企业管理员权限
        /// </summary>
        /// <param name="cid">企业ID</param>
        /// <param name="uid">用户ID</param>
        /// <param name="iscreater">是否超级管理员</param>
        /// <param name="authorities">权限集合</param>
        /// <returns>更新是否成功</returns>
        bool SetCorpManagerAuth(int cid, int uid, bool iscreater, string authorities);
        /// <summary>
        /// 获取权限实体
        /// </summary>
        /// <param name="cid">企业ID</param>
        /// <param name="uid">用户ID</param>
        /// <returns>权限实体</returns>
        IDataReader GetAuthInfo(int cid, int uid);
        /// <summary>
        /// 获取企业管理员权限
        /// </summary>
        DataTable GetCorpManagerAuthList(int pageindex, int pagesize, string condition);
        /// <summary>
        /// 根据条件企业管理员数量
        /// </summary>
        int GetCorpManagerAuthCount(string condition);
        /// <summary>
        /// 批量删除企业管理员
        /// </summary>
        void DeleteCorpManagerAuth(string idsparm);
        /// <summary>
        /// 根据用户ID获取用户权限列表
        /// </summary>
        IDataReader GetAuthListByUid(int uid);
        #endregion
        #region 用户组操作
        /// <summary>
        /// 创建新用户组.
        /// </summary>
        /// <param name="usergroupinfo">用户组信息</param>
        /// <returns>返回用户组ID, 如果已存在该用户名则返回-1</returns>
        int CreateUserGroup(UserGroupInfo usergroupinfo);
        /// <summary>
        /// 根据用户组名获取用户组信息
        /// </summary>
        /// <param name="usergroupName">用户组名</param>
        /// <returns></returns>
        IDataReader GetUserGroupInfoByName(string usergroupName);
        /// <summary>
        /// 获取用户组数据
        /// </summary>
        DataTable GetUserGroupList(string strWhere);

        /// <summary>
        /// 删除用户组信息
        /// </summary>
        /// <param name="ids">用户组id组合</param>
        /// <returns></returns>
        int DelUserGroup(string ids);
        bool UpdateUserGroup(UserGroupInfo uginfo);
        #endregion

        #region 企业信息操作
        /// <summary>
        /// 创建企业信息
        /// </summary>
        int CreateCompany(CompanyInfo cinfo);
        /// <summary>
        /// 根据查询条件获取企业数量
        /// </summary>
        int GetCompanyCountByCondition(string querystring);
        /// <summary>
        /// 企业数据分页操作
        /// </summary>
        DataTable GetCompanyPageList(int pageindex, int pagesize, string conditions, string orderstr);
        /// <summary>
        /// 获取企业信息
        /// </summary>
        IDataReader GetCompanyByID(int id);
        /// <summary>
        /// 更新企业信息
        /// </summary>
        void UpdateCompany(CompanyInfo cinfo);
        /// <summary>
        /// 根据用户组ID返回用户组实体
        /// </summary>
        IDataReader GetUserGroupInfoByID(int gid);
        /// <summary>
        /// 删除企业信息
        /// </summary>
        /// <param name="ids">企业id组合</param>
        /// <returns></returns>
        int DelCompany(string ids);
        /// <summary>
        /// 判断企业是否存在
        /// </summary>
        int IsExistCompany(string companyname);
        /// <summary>
        /// 更改企业状态
        /// </summary>
        bool UpdateCorpStatus(string ids, int status);
        /// <summary>
        /// 设置企业积分
        /// </summary>
        int SetCorpScore(int cid, int scores);
        #endregion

        #region 基础类型操作
        /// <summary>
        /// 创建基础类型
        /// </summary>
        /// <param name="code">类型代码</param>
        /// <param name="tname">类型名称</param>
        /// <param name="ename">类型英文</param>
        /// <param name="extends">类型扩展</param>
        /// <returns></returns>
        string CreateBaseType(string code, string tname, string ename, string extends);
        /// <summary>
        /// 根据Code是否存在
        /// </summary>
        /// <param name="code"></param>
        IDataReader GetBaseTypeCode(string code);
        /// <summary>
        /// 修改基础类型信息
        /// </summary>
        void UpdateBaseType(string code, string tname, string ename, string extends);
        /// <summary>
        /// 基础类型分页
        /// </summary>
        DataTable GetBaseTypesByPage(int pageindex, int pagesize, string condition, string orderstr);
        /// <summary>
        /// 基础类型数量
        /// </summary>
        int GetBaseTypeCount(string conditions);

        /// <summary>
        /// 删除基础类型
        /// </summary>
        int DelBaseType(string bcode);
        /// <summary>
        /// 根据基础类型code查询是否有基础数据
        /// </summary>
        DataTable GetBaseDataByTypecode(string bcode);

        #endregion

        #region 基础数据操作
        /// <summary>
        /// 创建基础数据
        /// </summary>
        int CreateBaseData(BaseDataInfo binfo);
        /// <summary>
        /// 查询当前数据是否唯一
        /// </summary>
        /// <param name="code">数据代码</param>
        /// <param name="tcode">数据类型</param>
        bool ExistBaseData(string code, string tcode);
        /// <summary>
        /// 修改基础数据
        /// </summary>
        /// <param name="binfo"></param>
        void UpdateBaseData(BaseDataInfo binfo);
        /// <summary>
        /// 基础数据分页
        /// </summary>
        DataTable GetBaseDataByPage(int pageindex, int pagesize, string condition, string orderstr);
        /// <summary>
        /// 基础数据数量
        /// </summary>
        int GetBaseDataCount(string conditions);
        int GetCompBaseDataCount(string conditions);
        /// <summary>
        /// 根据ID获取基本数据信息实体
        /// </summary>
        IDataReader GetBaseDataByID(int bid);
        /// <summary>
        /// 根据ID获取基本数据信息实体
        /// </summary>
        IDataReader GetBaseDataByStr(string strWhere);
        /// <summary>
        /// 删除基础数据
        /// </summary>
        /// <param name="ids">基础数据id组合</param>
        /// <returns></returns>
        int DelBaseData(string ids);
        DataTable GetBaseDataListByStr(string condition);
        DataTable GetDestportsMsg(string strWhere);
        DataTable GetCompBaseDataListByStr(int pageindex, int pagesize, string condition, string orderstr);
        /// <summary>
        /// 返回基础数据查询基本条件
        /// </summary>
        /// <param name="scode">基础数据类型code(必填）</param>
        /// <param name="hxstr">航线集合</param>
        /// <param name="searchcname">检索中文名</param>
        /// <param name="searchename">检索英文名</param>
        /// <param name="datatype">数据查询类型</param>
        string GetBaseDataCondation(string scode, string hxstr, string searchcname, string searchename, int datatype);
        #endregion

        #region 航线授权信息操作
        /// <summary>
        /// 创建航线授权信息
        /// </summary>
        int CreateRoute(RouteInfo rinfo);
        /// <summary>
        /// 判断航线重复授权
        /// </summary>
        /// <param name="cid">公司ID</param>
        /// <param name="tcode">航线Code</param>
        /// <param name="bcode">船公司code</param>
        bool ExistReRoute(int cid, string tcode, string bcode);
        /// <summary>
        /// 根据ID获取授权信息
        /// </summary>
        IDataReader GetRountByID(int id);
        /// <summary>
        /// 获取航线授权信息分页
        /// </summary>
        DataTable GetRoutesByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype);
        /// <summary>
        /// 根据条件获取航线授权信息集合数量
        /// </summary>
        int GetRoutesCount(string conditions);
        /// <summary>
        /// 修改航线授权信息
        /// </summary>
        int UpdateRoute(RouteInfo rinfo);
        /// <summary>
        /// 根据条件获取授权信息
        /// </summary>
        IDataReader GetRountByStr(string strWhere);
        /// <summary>
        /// 删除航线授权信息
        /// </summary>
        /// <param name="ids">航线授权id组合</param>
        /// <returns></returns>
        int DelRoutes(string ids);
        /// <summary>
        /// 根据条件获取授权信息
        /// </summary>
        DataTable GetRountTabByStr(string strWhere);
        /// <summary>
        /// 根据条件获取授权信息
        /// </summary>
        IDataReader GetRountList(string strWhere);
        int AddRoute(DataTable dt);
        #endregion

        #region 航线基本信息操作
        /// <summary>
        /// 创建航线信息
        /// </summary>
        int CreateRouteBase(RouteBaseInfo rinfo);
        /// <summary>
        /// 航线基本信息分页操作
        /// </summary>
        IDataReader GetRouteBaseListByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype);
        /// <summary>
        /// 航线基本信息分页操作
        /// </summary>
        IDataReader GetRouteBaseSearchByPage(int type, int oid, int cid, int pageindex, int pagesize, string condition, string ordercolumn, string ordertype);
        /// <summary>
        /// 航线基本信息分页操作(table)
        /// </summary>
        DataTable GetRouteBaseSearchTableByPage(int type, int oid, int cid, int pageindex, int pagesize, string condition, string ordercolumn, string ordertype);
        /// <summary>
        /// 航线基本信息分页操作
        /// </summary>
        DataTable GetRouteBaseTableByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype);
        /// <summary>
        /// 航线数量
        /// </summary>
        int GetRouteBasesCount(string conditions);
        /// <summary>
        /// 搜索航线数量
        /// </summary>
        int GetRouteBaseListCount(int type, int oid, string conditions);
        /// <summary>
        /// 修改航线信息
        /// </summary>
        /// <param name="rbinfo"></param>
        /// <returns></returns>
        int UpdateRouteBase(RouteBaseInfo rbinfo);
        /// <summary>
        /// 快捷价格修改
        /// </summary>
        /// <param name="rid">线路ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        int UpdateRouteBasePrice(int rid, string price1, string price2, string price3);
        /// <summary>
        /// 获取航线实体信息
        /// </summary>
        IDataReader GetRouteBaseInfo(int id);
        /// <summary>
        /// 获取搜索航线实体信息
        /// </summary>
        IDataReader GetSearchRouteBaseInfo(int id, int type, int oid, int cid);
        int DelRouteBase(string ids);
        int UpdateRouteBaseStatus(string ids, int val);
        /// <summary>
        /// 搜索条件生成
        /// </summary>
        /// <param name="cid">所属公司ID</param>
        /// <param name="isuse">是否启用（-1为不限，0为未启用，1，为启用中）</param>
        /// <param name="loadport">起运港口</param>
        /// <param name="objectport">目的港口</param>
        /// <param name="routeline">航线</param>
        /// <param name="corp">船公司</param>
        string GetRouteBaseCondation(int cid, int isuse, string loadport, string objectport, string routeline, string corp);
        /// <summary>
        /// 批量修改线路价格信息
        /// </summary>
        int UpdateBatchRoutePrice(RouteBaseInfo rinfo, string ids);
        /// <summary>
        /// 批量修改线路基本信息
        /// </summary>
        int UpdateBatchRouteInfo(RouteBaseInfo rinfo, string ids);
        #endregion

        #region 规则操作
        /// <summary>
        /// 增设规则
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="oid">企业ID</param>
        /// <param name="rtype">规则类型</param>
        /// <param name="_20GP">20GP价格</param>
        /// <param name="_40GP">40GP价格</param>
        /// <param name="_40HQ">40HQ价格</param>
        /// <param name="rid">航线ID</param>
        /// <param name="port">港口</param>
        int CreateRules(int uid, int oid, int rtype, string _20GP, string _40GP, string _40HQ, int rid, string port, string seacode);
        /// <summary>
        /// 是否存在规则信息
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="oid">企业ID</param>
        /// <param name="rtype">规则类型</param>
        /// <param name="rid">航线ID</param>
        /// <param name="port">港口</param>
        bool ExistRule(int uid, int oid, int rtype, int rid, string port, string seacode);
        /// <summary>
        /// 获取规则数量
        /// </summary>
        int GetRulesCount(string condition);
        /// <summary>
        /// 规则基本信息分页操作（DataTable对象)
        /// </summary>
        DataTable GetRulesByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype);
        /// <summary>
        /// 批量删除操作
        /// </summary>
        void DeleteRulesByIds(string ids);
        /// <summary>
        /// 获取规则实体
        /// </summary>
        IDataReader GetRuleInfoByID(int id);
        /// <summary>
        /// 修改规则价格设置
        /// </summary>
        void UpdateRulePrice(int id, string price1, string price2, string price3);
        /// <summary>
        /// 其他公司航线价格分页操作
        /// </summary>
        DataTable GetRoutePriceRuleByPage(int type, int uid, int cid, int pageindex, int pagesize, string condition, string ordercolumn, string ordertype);
        /// <summary>
        /// 其他公司线路价格规则批量调整
        /// </summary>
        /// <param name="ids">线路ID集合</param>
        void UpdateRules(string ids, int uid, string price1, string price2, string price3);
        /// <summary>
        /// 其他公司线路价格规则批量调整（用户批量）
        /// </summary>
        void UpdateRules(string ids, string uids, string price1, string price2, string price3);
        #endregion

        #region onlineuser 在线用户操作
        /// <summary>
        /// 创建在线表记录(本方法在应用程序初始化时被调用)
        /// </summary>
        /// <returns></returns>
        int CreateOnlineTable();
        IDataReader GetOnlineUserByID(int oid);
        /// <summary>
        /// 添加在线用户
        /// </summary>
        /// <param name="onlineuserinfo">在组用户信息内容</param>
        /// <param name="timeout">过期时间</param>
        /// <returns></returns>
        int AddOnlineUser(OnlineUserInfo onlineUserInfo, int timeOut, int deletingFrequency);
        /// <summary>
        /// 设置用户在线状态
        /// </summary>
        /// <param name="uid">在线用户id</param>
        /// <param name="onlineState">在线用户状态</param>
        /// <returns></returns>
        int SetUserOnlineState(int uid, int onlineState, string vcode);
        /// <summary>
        /// 更新用户IP地址
        /// </summary>
        /// <param name="olId">在线id</param>
        /// <param name="ip">ip地址</param>
        void UpdateIP(int olId, string ip);
        /// <summary>
        /// 获取在线用户信息
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="passWord"></param>
        /// <returns></returns>
        DataTable GetOnlineUser(int userId, string passWord);
        /// <summary>
        /// 删除在线表中的一行
        /// </summary>
        /// <param name="ip"></param>
        /// <returns>删除行数</returns>
        int DeleteRowsByIP(string ip);

        /// <summary>
        /// 删除在线表中的一行
        /// </summary>
        /// <param name="olId">在线id</param>
        /// <returns></returns>
        int DeleteRows(int olId);
        /// <summary>
        /// 获取在线用户信息
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="ip"></param>
        /// <returns>用户的详细信息</returns>
        DataTable GetOnlineUserByIP(int userId, string ip);
        /// <summary>
        /// 检查用户验证码
        /// </summary>
        /// <param name="olId">在组用户ID</param>
        /// <param name="verifyCode">验证码</param>
        /// <param name="newverifyCode">新验证码</param>
        /// <returns></returns>
        bool CheckUserVerifyCode(int olId, string verifyCode, string newverifyCode);
        /// <summary>
        /// 更新在线时间
        /// </summary>
        /// <param name="olTimeSpan">在线时间间隔</param>
        /// <param name="uid">当前用户id</param>
        void UpdateOnlineTime(int olTimeSpan, int uid);
        /// <summary>
        /// 同步在线时间
        /// </summary>
        /// <param name="uid">用户id</param>
        void SynchronizeOnlineTime(int uid);
        /// <summary>
        /// 更新在线操作
        /// </summary>
        void UpdateAction(int olid, int actid);
        /// <summary>
        /// 删除指定在线用户信息
        /// </summary>
        /// <param name="uid"></param>
        void DeleteRowsByUid(int uid);
        #endregion

        #region 日志操作
        /// <summary>
        /// 创建访问日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="gid">组ID</param>
        /// <param name="cid">访问企业ID</param>
        /// <param name="ip">访问IP</param>
        /// <param name="actid">访问动作</param>
        /// <param name="actdesc">具体内容描述</param>
        /// <returns>日志ID</returns>
        int CreateVisitLog(int uid, string lname, int gid, int cid, string ip, int actid, string actstr, string actdesc);
        /// <summary>
        /// 根据条件获取全部企业管理员访问日志集合数量
        /// </summary>
        int GetAllCompanyVisitLogCount(string querystring);
        /// <summary>
        /// 获取全部企业管理员访问日志分页操作
        /// </summary>
        DataTable GetAllCompanyVisitLogsByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype);
        /// <summary>
        /// 删除访问日志
        /// </summary>
        void DelVisitLog(string ids);
        /// <summary>
        /// 创建线路信息日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="rid">新增线路ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        /// <param name="actid">动作ID</param>
        /// <param name="logstr">动作描述</param>
        int CreateRouteLog(int uid, string lname, int rid, string price1, string price2, string price3, int actid, string actstr, string actdesc);
        /// <summary>
        /// 根据条件获取全部企业线路操作日志集合数量
        /// </summary>
        int GetAllRouteLogCount(string querystring);
        /// <summary>
        /// 获取全部企业线路操作日志分页操作
        /// </summary>
        DataTable GetRouteLogsByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype);
        /// <summary>
        /// 删除线路操作日志
        /// </summary>
        void DelRouteLogs(string ids);
        /// <summary>
        /// 根据条件获取线路日志集合
        /// </summary>
        DataTable GetRouteLogTable(string conditions);
        /// <summary>
        /// 根据条件获取线路日志集合
        /// </summary>
        IDataReader GetRouteLogReader(string conditions);
        /// <summary>
        /// 创建规则日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="cid">规则所属公司</param>
        /// <param name="rid">规则ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        /// <param name="actid">动作ID</param>
        /// <param name="actdesc">动作描述</param>
        int CreateRuleLog(int uid, string lname, int cid, int rid, string price1, string price2, string price3, int actid, string actstr, string actdesc);
        /// <summary>
        /// 根据条件获取全部企业规则操作日志集合数量
        /// </summary>
        int GetAllRuleLogCount(string querystring);
        /// <summary>
        /// 获取全部企业规则操作日志分页操作
        /// </summary>
        DataTable GetRuleLogsByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype);
        /// <summary>
        /// 删除规则操作日志
        /// </summary>
        void DelRuleLogs(string ids);
        /// <summary>
        /// 创建用户搜索日志
        /// </summary>
        /// <param name="uid">用户ID（-1为匿名用户）</param>
        /// <param name="lname">登录名</param>
        /// <param name="visitip">访问IP</param>
        /// <param name="stype">搜索类型（默认0为整柜）</param>
        /// <param name="dportkey">目的港关键字</param>
        /// <param name="lportkey">起运港关键字</param>
        /// <param name="routeline">航线</param>
        /// <param name="boatcorp">船公司</param>
        /// <param name="oid">对象ID（整柜为线路ID）</param>
        /// <param name="actid">动作ID</param>
        /// <param name="actions">动作名称</param>
        /// <param name="acotent">动作内容</param>
        /// <param name="searchcode">编号（整柜指线路编号）</param>
        /// <returns>日志ID</returns>
        int CreateUserVisitLog(int uid, string lname, string visitip, int stype, string dportkey, string lportkey, string routeline, string boatcorp, int oid, int actid, string actions, string acotent, string searchcode);
        /// <summary>
        /// 根据条件获取用户搜索日志集合
        /// </summary>
        int GetAllUserVisitLogCount(string querystring);
        /// <summary>
        /// 获取全部用户搜索日志分页操作
        /// </summary>
        DataTable GetAllUserVisitLogsByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype);
        /// <summary>
        /// 删除用户搜索操作日志
        /// </summary>
        void DelUserVisitLogs(string ids);
        #endregion

        #region 静态统计操作
        /// <summary>
        /// 根据企业ID获取企业统计信息
        /// </summary>
        IDataReader GetStaticInfoByCid(int cid);
        #endregion
    }
}
